<template>
	<view class="container">
		<uni-section title="食物轮播图展示" type="line">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="item in list">
					<image :src="'http://localhost:8090'+item.icon" mode="" style="width: 100%;height: 150px;"></image>
				</swiper-item>
			</swiper>
		</uni-section>
		<uni-section title="食物类别宫格展示" type="line">
			<uni-grid :column="3">
				<uni-grid-item v-for="item in foods">
					<view class=""
						style="display: flex;flex-direction: column;align-items: center;justify-content: center;flex: 1;">
						<image :src="'http://localhost:8090'+item.icon" mode="" style="width: 70px;height: 70px;">
						</image>
						<view class="">{{item.typename}}</view>
					</view>
				</uni-grid-item>
			</uni-grid>
		</uni-section>
		<uni-section :title="'食物列表展示('+foods1.length+'条)'" type="line">
			<uni-list>
				<uni-list-item clickable @click="show(item.id)" v-for="item in foods1"
					:thumb="'http://localhost:8090'+item.icon" :title="item.name" :right-text="'￥'+item.price+'元'">
				</uni-list-item>
			</uni-list>
		</uni-section>
		<uni-section :title="'食物评论列表展示('+comment.length+'条)'" type="line">
			<uni-list>
				<uni-list-item v-for="item in comment" :title="item.comment" note="" :right-text="item.postdate">
				</uni-list-item>
			</uni-list>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				foods: [],
				foods1: [],
				comment: []
			}
		},
		methods: {
			show(id) {
				uni.navigateTo({
					url: '/pages/food/fooddetail/fooddetail?id=' + id
				});
			}
		},
		onLoad() {
			uni.request({
				url: 'http://localhost:8090/foodapp/foodSwiper/list',
				method: 'POST',
				data: {},
				success: res => {
					this.list = res.data.list
					if (res.data.success) {
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {},
				complete: () => {}
			});
			uni.request({
				url: 'http://localhost:8090/foodapp/foodType/list',
				method: 'POST',
				data: {},
				success: res => {
					this.foods = res.data.list
					if (res.data.success) {
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {},
				complete: () => {}
			});
			uni.request({
				url: 'http://localhost:8090/foodapp/food/list',
				method: 'POST',
				data: {},
				success: res => {
					this.foods1 = res.data.list
					if (res.data.success) {
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {},
				complete: () => {}
			});
			uni.request({
				url: 'http://localhost:8090/foodapp/comment/list',
				method: 'POST',
				data: {},
				success: res => {
					this.comment = res.data.list
					if (res.data.success) {
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {},
				complete: () => {}
			});
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
